package com.thecafetechno.main;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.thecafetechno.university.Student;
import com.thecafetechno.university.Teacher;
import com.thecafetechno.util.HibernateUtil;

public class TPCHTester {
	public static void main(String[] args) {
		Student firstStudent= new Student();
		Student secondStudent= new Student();

		Teacher firstTeacher = new Teacher();
		Teacher secondTeacher = new Teacher();
		
		firstStudent.setName("Saurabh");
		firstStudent.setYear(2);
		firstStudent.setDepartment("CSE");
	
		secondStudent.setName("Pushpi");
		secondStudent.setYear(3);
		secondStudent.setDepartment("CSE");
			
		firstTeacher.setExperience(4);
		firstTeacher.setName("Dr. RNath");
		firstTeacher.setSpecialization("Java");
		firstTeacher.setDepartment("CSE");

		secondTeacher.setExperience(4);
		secondTeacher.setName("Priyanka");
		secondTeacher.setSpecialization("Java");
		secondTeacher.setDepartment("CSE");
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction transaction = session.beginTransaction();
		Serializable id = session.save(firstStudent);
		session.save(secondStudent);
		session.save(firstTeacher);
		session.save(secondTeacher);
		transaction.commit();
		
		session = HibernateUtil.getSessionFactory().openSession();
		transaction = session.beginTransaction();
		Student resultStudent = (Student)session.load(Student.class, id);
		transaction.commit();
		
		System.out.println("Student is : "+ resultStudent);
	}
}
